<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('退出决策') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input v-model="queryParams.actTitle" :placeholder="$t('申请标题')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('退出策略')" prop="exitStrategy">
        <dictSelect
          v-model="queryParams.exitStrategy"
          :clearable="true"
          dictionary="deal_exit_strategy"
        />
      </el-form-item>
      <!--      <el-form-item :label="$t('受让方')" prop="transferee">
        <el-input
          v-model="queryParams.transferee"
          :placeholder="$t('受让方')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('退出方式')" prop="exitMode">
        <el-select v-model="queryParams.exitMode" :placeholder="$t('退出方式')" clearable>
          <el-option
            v-for="dict in exitModeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item :label="$t('拟退出时间')" prop="draftExitTime" label-width="120">
        <DatePicker v-model="draftExitTimes" type="daterange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:exit:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['deal:exit:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealExitList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('拟退出时间')" align="center" prop="draftExitTime" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.draftExitTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('拟退出持股比例(%)')" align="center" prop="draftExitShareholdingRatio" show-overflow-tooltip width="140" />
      <el-table-column :label="$t('拟退出金额') + $t('金额单位')" align="center" prop="draftExitPrice" show-overflow-tooltip width="110">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.draftExitPrice, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('优先退出方式')" align="center" prop="priorWay" :formatter="priorFormat" show-overflow-tooltip width="130" />
      <el-table-column :label="$t('备选退出方式')" align="center" prop="spareWay" :formatter="spareFormat" show-overflow-tooltip width="130" />
      <el-table-column :label="$t('保底退出方式')" align="center" prop="lowestWay" :formatter="lowestFormat" show-overflow-tooltip width="130" />
      <el-table-column :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="deal:exit" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改退出申请对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealExitForm ref="dealExitForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealExit, delDealExit } from '@/api/sass/kaihui/exit/kaiHuiDealExit'
import ProcessStatus from '@/components/Act/ProcessStatus'
import dealExitForm from './kaiHuiDealExitForm.vue'
export default {
  components: {
      dealExitForm,
      ProcessStatus
  },
  data() {
    return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 退出申请表格数据
        dealExitList: [],
        // 拟退出时间 查询参数
        draftExitTimes: [],
        // 弹出层标题
        title: '退出决策',
        // 是否显示弹出层
        formOpen: false,
        // 退出方式字典
        exitWayOptions: [],
        // 查询参数
        queryParams: {
            exitStrategy: undefined,
            transferee: undefined,
            exitMode: undefined,
            startDate: undefined,
            endDate: undefined,
            dealId: this.$route.query.id,
            pageNum: 1,
            pageSize: 10
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          draftExitTime: [
            { required: true, message: this.$t('必填信息'), trigger: 'blur' }
          ], draftExitShareholdingRatio: [
            { required: true, message: this.$t('必填信息'), trigger: 'blur' }
          ], draftExitPrice: [
            { required: true, message: this.$t('必填信息'), trigger: 'blur' }
          ], exitMode: [
            { required: true, message: this.$t('必填信息'), trigger: 'blur' }
          ], transferee: [
            { required: true, message: this.$t('必填信息'), trigger: 'blur' }
          ]
        }
      }
  },
  created() {
      this.getList()
      this.getDicts('exit_plan_item').then(response => {
          this.exitWayOptions = response.data
      })
  },
  methods: {
    /** 查询退出申请列表 */
    getList() {
        this.loading = true
        if (this.draftExitTimes != null && this.draftExitTimes.length > 1) {
          this.queryParams.startDate = this.draftExitTimes[0]
          this.queryParams.endDate = this.draftExitTimes[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listDealExit(this.queryParams).then(response => {
            this.dealExitList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 退出方式字典翻译
    // eslint-disable-next-line no-unused-vars
    priorFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.priorWay)
    },
    spareFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.spareWay)
    },
    lowestFormat(row) {
      return this.selectDictLabel(this.exitWayOptions, row.lowestWay)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            dealBase: {
              id: undefined,
              dealName: ''
            },
            totalInvestment: undefined,
            userId: undefined,
            deptId: undefined,
            investmentTime: undefined,
            latestShareholdingRatio: undefined,
            reinvestmentCost: undefined,
            exitTotal: undefined,
            draftExitTime: undefined,
            draftExitShareholdingRatio: undefined,
            draftExitPrice: undefined,
            exitMode: undefined,
            exitSharesNumber: undefined,
            expectPerSharePrice: undefined,
            transferee: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.draftExitTimes = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealExitForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealExitForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealExit(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        this.downLoadExcel('/exit/kaiHuiDealExit/export', this.queryParams)
    }
  }
}
</script>
